home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / Extension Shell 1.3 / Sample Extensions / CircleMouse ][ ƒ / Circle VBL ][.c next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  3.4 KB  |  158 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         CircleMouse ][.c
  3.  
  4.     WRITTEN BY:
  5.         Mark Pilgrim
  6.                 
  7.     MODIFIED BY:
  8.         Dair Grant
  9.                 
  10.     DESCRIPTION:
  11.         This file contains a CODE resource to be installed as a VBL task.
  12.  
  13.     NOTES:
  14.         •    Causes the cursor to move in a circle when the mouse button is
  15.             pressed.
  16.  
  17.     ___________________________________________________________________________
  18.  
  19.     VERSION HISTORY:
  20.         (Jan 1994, dg)
  21.             •    Source to this module was taken from Mark's MouseBroken cdev
  22.                 source. It was altered slightly for use with Extension Shell.
  23.  
  24.  
  25.     ___________________________________________________________________________
  26. */
  27. //=============================================================================
  28. //        Include files                                                                     
  29. //-----------------------------------------------------------------------------
  30. #include <Retrace.h>
  31. #include <GestaltEQU.h>
  32. #include "StandaloneCode.h"
  33. #include "CodeConstants.h"
  34.  
  35.  
  36.  
  37.  
  38.  
  39. //=============================================================================
  40. //        Private function prototypes                                                                     
  41. //-----------------------------------------------------------------------------
  42. void    main(void);
  43. Boolean CapsKeyDown(void);
  44.  
  45.  
  46.  
  47.  
  48.  
  49. //=============================================================================
  50. //        Private defines                                                             
  51. //-----------------------------------------------------------------------------
  52. #define kRadius        5                // Actual radius is (1+2+...+(kRadius-1))+(kRadius/2)
  53. #define kTimeDelay    1
  54.  
  55.  
  56.  
  57.  
  58.  
  59. //=============================================================================
  60. //        Global variables                                                                 
  61. //-----------------------------------------------------------------------------
  62. extern Boolean    CrsrNew        : 0x8CE;            // Low memory globals
  63. extern Point    mTemp        : 0x828;
  64. extern Point    RawMouse    : 0x82C;
  65.  
  66. Boolean            gAlreadyRan=false;
  67. int                gVx,gVy;
  68. Boolean            gXIncreasing, gYIncreasing;
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. //=============================================================================
  80. //        main : Does the actual work.                                                                 
  81. //-----------------------------------------------------------------------------
  82. void main(void)
  83. {    VBLTask*        myVBL;
  84.     
  85.     
  86.     
  87.     
  88.     // Get our globals, and save the registers.
  89.     PatchGetGlobals();
  90.  
  91.  
  92.  
  93.     // Move the pointer to the VBLTask into our local variable
  94.     asm {
  95.         move.l d0, myVBL
  96.     }
  97.  
  98.  
  99.     
  100.     // If we've not already been called, prime ourselves
  101.     if (!gAlreadyRan)
  102.         {
  103.         gVx    = kRadius;
  104.         gVy    = 0;
  105.         gXIncreasing = false;
  106.         gYIncreasing = true;
  107.         gAlreadyRan    = true;
  108.         }
  109.  
  110.  
  111.  
  112.     // If the mouse button is down, and the caps lock key isn't - rotate    
  113.     if (Button() && !CapsKeyDown())
  114.         {
  115.         RawMouse.h    += gVx;
  116.         mTemp.h        += gVx;
  117.         RawMouse.v    += gVy;
  118.         mTemp.v        += gVy;
  119.         
  120.         gVx += gXIncreasing ? 1 : -1;
  121.         gVy += gYIncreasing ? 1 : -1;
  122.         
  123.         gXIncreasing = (gVx == kRadius) ? false : (gVx == -kRadius) ? true : gXIncreasing;
  124.         gYIncreasing = (gVy == kRadius) ? false : (gVy == -kRadius) ? true : gYIncreasing;
  125.         
  126.         CrsrNew = true;
  127.     }
  128.  
  129.     
  130.     
  131.     // Reset our delay, restore A4 and other registers, and return
  132.     myVBL->vblCount = kTimeDelay;
  133.     PatchUngetGlobals();
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. //=============================================================================
  146. //        CapsKeyDown : Returns true if the Caps-lock key is down.                                                             
  147. //-----------------------------------------------------------------------------
  148. Boolean CapsKeyDown(void)
  149. {    unsigned char    theKeys[16];
  150.     short            theCapsKey=57;
  151.  
  152.  
  153.  
  154.  
  155.    GetKeys((void *) theKeys);
  156.    return((theKeys[theCapsKey >> 3] >> (theCapsKey & 7)) & 1);
  157. }
  158.